package org.lhh.server.controller;

import org.lhh.server.annotation.LogCatch;
import org.lhh.server.annotation.UserAuth;
import org.lhh.server.common.api.JSONResult;
import org.lhh.server.core.codec.cluster.ClusterSchemaCodec;
import org.lhh.server.service.IClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/cluster")
public class ClusterController {

    @Autowired
    private IClusterService clusterService;

    @UserAuth
    @LogCatch(value = "服务集群-集群列表")
    @GetMapping("/list")
    public JSONResult list() {
        return clusterService.list();
    }

    @UserAuth
    @LogCatch(value = "服务集群-集群保存")
    @PutMapping("/save")
    public JSONResult save(@RequestBody ClusterSchemaCodec clusterSchemaCodec) {
        clusterService.saveClusterSchema(clusterSchemaCodec);
        return JSONResult.ok();
    }

    @UserAuth
    @LogCatch(value = "服务集群-集群删除")
    @DeleteMapping("/delete/{id}")
    public JSONResult list(@PathVariable Long id) {
        clusterService.remove(id);
        return JSONResult.ok();
    }

}
